package com.zmn.plat.services.impl.base.faultphenomenon;

import com.zmn.common.utils.date.DateUtil;
import com.zmn.plat.model.entity.base.phenomenon.PhenomenonFault;
import com.zmn.plat.model.entity.base.phenomenon.PhenomenonFaultQuery;
import com.zmn.plat.model.vo.base.phenomenon.PhenomenonFaultVO;
import com.zmn.plat.persistence.interfaces.base.phenomenon.PhenomenonFaultDao;
import com.zmn.plat.services.interfaces.base.phenomenon.PhenomenonFaultService;
import org.springframework.util.CollectionUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;
import com.zmn.common.constant.GlobalConsts;

/**
 * 描述: 故障现象-故障管理接口实现类
 *
 * @author chengguang
 * @since  2021/11/19 10:38
 */
@Slf4j
@Service
public class PhenomenonFaultServiceImpl implements PhenomenonFaultService {

    private static final String TAG = "故障现象-故障管理基础服务接口";

    @Resource
    private PhenomenonFaultDao phenomenonFaultDao;

    @Override
    public PhenomenonFault findById(Integer relateId) {
        if (Objects.isNull(relateId)) {
            log.error("[{}],根据id查询数据relateId为null", TAG);
            return null;
        }
        return phenomenonFaultDao.findById(relateId);
    }

    @Override
    public List<PhenomenonFault> listByIds(List<Integer> relateIds) {
        if (CollectionUtils.isEmpty(relateIds)) {
            log.error("[{}],按条件查询数据,relateIds为null", TAG);
            return null;
        }
        return phenomenonFaultDao.listByIds(relateIds);
    }

    @Override
    public List<PhenomenonFault> listByQuery(PhenomenonFaultQuery query) {
        if (Objects.isNull(query)) {
            log.error("[{}],按条件查询数据,query为null", TAG);
            return null;
        }
        return phenomenonFaultDao.listByQuery(query);
    }

    @Override
    public List<PhenomenonFault> listByPhenIds(List<Integer> phenIds) {
        return phenomenonFaultDao.listByphenIds(phenIds);
    }

    @Override
    public List<PhenomenonFault> listPageByQuery(PhenomenonFaultQuery query) {
        if (Objects.isNull(query)) {
            log.error("[{}],按条件查询数据,query为null", TAG);
            return null;
        }
        query.setTotalCount(phenomenonFaultDao.countByQuery(query));
        return phenomenonFaultDao.listPageByQuery(query);
    }

    @Override
    public List<PhenomenonFaultVO> listFaultNameAndIdByphenIds(List<Integer> phenIds) {
        return phenomenonFaultDao.listFaultNameAndIdByphenIds(phenIds);
    }

    @Override
    public Integer countByQuery(PhenomenonFaultQuery query) {
        if (Objects.isNull(query)) {
            log.error("[{}],按条件统计数据,query为null", TAG);
            return null;
        }
        return phenomenonFaultDao.countByQuery(query);
    }

    @Override
    public Integer updateByKey(PhenomenonFault phenomenonFault) {
        if (Objects.isNull(phenomenonFault.getRelateId())){
            log.error("[{}],根据id修改数据,PhenomenonFault为null", TAG);
            return null;
        }
        return phenomenonFaultDao.updateByKey(phenomenonFault);
    }

    @Override
    public void updateStatusBatch(List<Integer> ids, Integer status, String operator) {
        if (!Objects.equals(status, GlobalConsts.NO) && !Objects.equals(status, GlobalConsts.YES)) {
            log.error("[{}],status状态超出取值范围", TAG);
            return;
        }
        phenomenonFaultDao.updateStatusBatch(ids, status, operator, DateUtil.getNow());
    }

    @Override
    public void updateFaultNameByFaultId(Integer faultId, String faultName) {
        phenomenonFaultDao.updateFaultNameByFaultId(faultId,faultName);
    }

    @Override
    public Integer insert(PhenomenonFault phenomenonFault){
        if (Objects.isNull(phenomenonFault)){
            log.error("[{}],新增数据,PhenomenonFault为null", TAG);
            return null;
        }
        return phenomenonFaultDao.insert(phenomenonFault);
    }

    @Override
    public void insertBatch(List<PhenomenonFault> list){
        if (CollectionUtils.isEmpty(list)) {
            log.error("[{}],数据为空", TAG);
            return;
        }
        phenomenonFaultDao.insertBatch(list);
    }

    @Override
    public Integer deleteByKey(Integer relateId) {
        if (Objects.isNull(relateId)){
            log.error("[{}],根据id删除数据,relateId为null", TAG);
            return null;
        }
        return phenomenonFaultDao.deleteByKey(relateId);
    }

    @Override
    public Integer deleteByPhenId(Integer phenId) {
        if (Objects.isNull(phenId)){
            log.error("[{}],根据id删除数据,relateId为null", TAG);
            return null;
        }
        return phenomenonFaultDao.deleteByPhenId(phenId);
    }

    @Override
    public Integer deleteByFaultIds(List<Integer> FaultIds) {
        return phenomenonFaultDao.deleteByFaultIds(FaultIds);
    }

}